/*
                    TextBox Class Definition
*/

#ifndef TEXTBOX_H
#define TEXTBOX_H

#include <stdio.h>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_rotozoom.h"
#include <string>
#include "SDL/SDL_ttf.h"

#include "../Structs.h"
#include "../Functions.h"

#include "Widget.h"

using namespace std;

class TextBox : public Widget
{
    public:
        TextBox();
        ~TextBox();

        int Initialise(Point NewPosition, string strFontFilepath, int iNewSize,
                           int iNewPadding, string strImageFilepath, SDL_Color NewColor, int iNewCharacterLimit);

        int HandleMouseDown(int iMouseX, int iMouseY);
        int HandleKeyDown(string strKeyName, Uint16 UNICODEvalue);

        void setPosition(Point NewPosition);
        Point getPosition();

        void setValidInput(string strNewValidInput);
        UnicodeString& getValidInput();

        void setText(string strNewText);
        string getText();

        UnicodeString getString();

        bool HasFocus();

        void setPasswordbox(bool bNewVal);

        int BlitToSurface(SDL_Surface *screen);

        int BlitToFrame(SDL_Surface *surface, Point FramePosition);

    protected:
        TTF_Font *TTFfont;
        SDL_Surface *Image, *TTFText, *Cursor;

        SDL_Color ForeColour;

        UnicodeString ustrText;

        string strAltBuffer;

        Point Position, CursorPosition;

        bool bPasswordbox;

        int iWidth, iHeight;

        int iRenderX;

        int iSize, iPadding;

        int iCursorPosition;
        int iCameraPosition;

        int iCharacterLimit;

        bool bHasFocus;

        int UpdateTextBox();
        int ParseKey(string strKeyName, Uint16 ucharKeyName);
        bool isInput(Uint16 ucharKeyName);
        int MoveCursorRight();
        int MoveCursorLeft();
        int EraseLetter();
        int InsertCharacter(Uint16 ucharKeyName);
        int DeleteLetter();

        UnicodeString ustrValidInput;
};

#endif
